package com.runa.rccprotocol.dto.daiao;

import com.runa.protocol.util.ByteUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 2024/12/19 16:56
 * zhangYB
 */
@Slf4j
@Data
public class DaiAoMeterRequestData {


    public byte[] selectDaiAoMeter(String meter) {
        byte[] data = new byte[100];
        int i = 0;
        data[i++] = 0x68;
        data[i++] = 0x0B;
        data[i++] = 0x0B;
        data[i++] = 0x68;

        data[i++] = 0x53;
        data[i++] = (byte)0xFD;
        data[i++] = 0x52;

        byte[] bytes = ByteUtil.hexStringToByteFlip(meter);
        for (byte b : bytes) {
            data[i++] = b;
        }

        data[i++] = (byte)0xFF;
        data[i++] = (byte)0xFF;
        data[i++] = (byte)0xFF;
        data[i++] = (byte)0xFF;

        data[i++] = ByteUtil.sum(data, 4, i - 4);
        data[i++] = 0x16;
        return ByteUtil.slice(data, 0, i);
    }


    public byte[] readDaiAoMeter(String meter) {
        String s = "10 7B FD 78 16";
        return ByteUtil.hexStringToByte(s);
    }

    public byte[] unselectDaiAoMeter(String meter) {
        String s = "10 40 FD 3D 16";
        return ByteUtil.hexStringToByte(s);
    }


    public static void main(String[] args) {
        String meter = "42300866";
        DaiAoMeterRequestData requestData = new DaiAoMeterRequestData();
        byte[] bytes = requestData.selectDaiAoMeter(meter);
        System.out.println("选择表: " + ByteUtil.byteToHexString(bytes));

        bytes = requestData.readDaiAoMeter(meter);
        System.out.println("读取表: " + ByteUtil.byteToHexString(bytes));

        bytes = requestData.unselectDaiAoMeter(meter);
        System.out.println("取消表: " + ByteUtil.byteToHexString(bytes));


    }

}
